import java.awt.Graphics;
import java.awt.Image;

public class LadybugSprite extends BeeSprite {

	protected Image imageLadybugLeft;
	protected Image imageLadybugRight;
	protected Image deadLadybugLeft;
	protected Image deadLadybugRight;

	protected boolean isHit;
	protected boolean shouldDrawImage = false;

	public boolean getIsHit() {
		return isHit;
	}

	public void setIsHit(boolean isHit) {
		this.isHit = isHit;
	}

	public LadybugSprite(Gameloop gl) {
		super(gl);

		imageLadybugLeft = ImageLoader.get().read("/Images/LadybugLeft.png");
		imageLadybugRight = ImageLoader.get().read("/Images/LadybugRight.png");

		deadLadybugLeft = ImageLoader.get().read("/Images/DeadLadybugLeft.png");
		deadLadybugRight = ImageLoader.get().read(
				"/Images/DeadLadybugRight.png");

		speedx = 2.5f;
		speedy = 1.0f;

		maxlimit = 40;
		value = -5;
		isHit = false;

	}

	public void update() {

		if (isHit) {
			deadpath();
			shouldDrawImage = true;
			return;
		}

		if (++compteur % speedLimit == 0) {

			speedLimit = random.nextInt(maxlimit) + 1;

			flagy = random.nextBoolean();
			compteur = 0;
		}

		x = (int) (x + (speedx * (flagx ? 1 : -1)));
		y = (int) (y + (speedy * (flagy ? 1 : -1)));

	}

	public void draw(Graphics g) {

		if (!flagx && !isHit) {
			g.drawImage(imageLadybugLeft, x, y, width, height, null);
		} else if (flagx && !isHit) {
			g.drawImage(imageLadybugRight, x, y, width, height, null);
		} else if (isHit && !flagx) {
			g.drawImage(deadLadybugLeft, x, y, width, height, null);
		} else {
			g.drawImage(deadLadybugRight, x, y, width, height, null);
		}

	}

}
